<template>
	<view>
		<view class="mainpadding2">
			<view class="mainpadding_top ffffff radius">
				<view class="main_size bold hei_text">请输入要反馈的内容（5-500字以内）</view>
				<textarea cols="30" rows="10" placeholder="请输入" maxlength="500" class="hei_text main_size margin_top2"
					style="width: 100%; height: 200rpx;" v-model="des"></textarea>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="main_size bold hei_text">请提供问题的截图或图片（选填）</view>
				<view class="flexleft flex_wrap">
					<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in images_text" :key="index">
						<!-- 已上传 -->
						<view class="listleftimg">
							<image class="listleftimg radius" :src="item" mode=""></image>
							<view class="deleteimg" @click="deleteimg(images,images_text,index)"></view>
						</view>
					</view>
					<view class="itemimgBox flexcenter margin_top2" @click="uploadImg(4,images,images_text)"
						v-if="images_text.length!=4">
						<!-- 未上传 -->
						<image class="listleftimg radius" src="@/static/image/system/upimg.png" mode=""></image>
					</view>
				</view>
				<!-- <view class="flexleft flex_wrap">
					<view class="itemimgBox flexcenter margin_top" v-for="item in 3">
						<view class="listleftimg">
							<image class="listleftimg radius"
								src="https://xunbo.yuntaiqikeji.com/uploads/20230725/5f1a390c01eae149ad8ef40aa05efffa.jpg"
								mode="">
							</image>
							<view class="deleteimg"></view>
						</view>
					</view>
					<view class="itemimgBox flexcenter margin_top">
						<image class="listleftimg radius" src="../static/image/system/upimg.png" mode=""></image>
					</view>
				</view> -->
			</view>
			<view class="mainpadding_top ffffff flexbetween">
				<view class="main_size bold hei_text">联系方式</view>
				<input class="main_size  hei_text" type="number" placeholder="请输入" style="text-align: right;" v-model="mobile">
			</view>
		</view>
		<view class="posibottom mainpadding" style="bottom: 0;">
			<view class="xiaohui flexcenter" @click="jumpurl('/pages_mine/lishifk')">历史反馈</view>
			<view class="submitbtn margin_top" @click="submit">确认提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				images: [],
				images_text: [],
				des: "",
				mobile: "",
			}
		},
		methods: {
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value); 
				return a;
			},
			submit(){
				
				if (this.des == '') {
					httpRequest.toast("请输入反馈意见!")
					return;
				}
				if (this.des.length <= 4) {
					httpRequest.toast("反馈意见字数限制在5-500字以内!")
					return;
				}
				if (this.mobile == '') {
					httpRequest.toast("请输入手机号码!")
					return;
				}
				if (!this.isMobile(this.mobile)) {
					httpRequest.toast("手机号码格式错误!")
					return;
				}
				httpRequest.request('/api/member/feedback', 'POST', {
					content:this.des,
					images:this.images.length?this.images.join():"",
					contact:this.mobile,
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			},
			uploadImg(value, upImgs, upImgs_text) {
				let _this = this;
				let num = Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			deleteimg(upImg,upImgs_text,index){
				upImg.splice(index,1)
				upImgs_text.splice(index,1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url);
					upImgs_text.push(image_item);
			
				}).catch(err => {});
			},
		}
	}
</script>

<style>

</style>
